// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    // LIFE-CYCLE CALLBACKS:

    speed: number = 3 // 步长
    
    direction: cc.Vec2 = null // 方向

    onLoad () {
      // this.direction = cc.v2(1, 0)
    }

    start () {

    }

    update (dt) {
      if (this.direction === null) return false

      let dx = this.speed * this.direction.x
      let dy = this.speed * this.direction.y

      let pos = this.node.getPosition()
      pos.x += dx
      pos.y += dy
      this.node.setPosition(pos)
    }
}
